package com.example.demo.util;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.example.demo.controller.UserController;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PostMapping;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class TestAnno {

    public static void main(String[] args) throws NoSuchMethodException {
       /* Method method22 = UserController.class.getMethod("detail");
        Annotation[] annotations = method22.getAnnotations();

        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }*/

        try {
            Class<?> clazz = Class.forName("com.example.demo.controller.UserController");
            Method[] methods = clazz.getDeclaredMethods();
            for (Method method : methods) {
                Annotation[] annotations = method.getAnnotations();
                for (Annotation annotation : annotations) {
                    String annotationName = annotation.annotationType().getName();
                    System.out.println("Method：" + method.getName() + " 和annotation: " + annotationName);
                }
                SaCheckPermission ppoo = method.getAnnotation(SaCheckPermission.class);
                String[] value = ppoo.value();
                SaMode mode = ppoo.mode();
                Bean bean = method.getAnnotation(Bean.class);

                if (method.isAnnotationPresent(Bean.class)) {
                    System.out.println(method.getName() + " is a Before Advice method.");
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

}
